package com.caigou.servlet;

import java.io.IOException;
import java.io.OutputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jiliang.purchase.demo.think_liebiao;
import jiliang.purchase.demo.think_lingxing;
import jiliang.purchase.demo.think_shenhe;

import com.caigou.service.checkApplyService;
import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.Font;
import com.itextpdf.text.Image;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.BarcodeQRCode;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.ColumnText;
import com.itextpdf.text.pdf.PdfAnnotation;
import com.itextpdf.text.pdf.PdfAppearance;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfFormField;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.pdf.RadioCheckField;

public class PrintPdf extends HttpServlet {

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	private checkApplyService CKS = new checkApplyService();
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("application/pdf;charset=utf-8");

		String filedisplay = "list.pdf";
		response.addHeader("Content-Disposition", "attachment;filename="+ filedisplay);
		
		//通过bh(编号查看信息)
		String bh = request.getParameter("bh");
		//System.out.println(bh);
		think_lingxing tlx = new think_lingxing();
		tlx = CKS.getLingXing(bh);
		//System.out.println(tlx.getSq_id());
		List<think_liebiao> list = new ArrayList<think_liebiao>();
		list = CKS.getLieBiao(tlx.getSq_id());
		List<think_shenhe> list1 = new ArrayList<think_shenhe>();
		list1 = CKS.getShenHe(tlx.getSq_id());
			
		try {
			CreatePDF(tlx,list,list1,getTime(tlx.getEditsj()),response.getOutputStream());
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request,response);
	}
	
	public void CreatePDF(think_lingxing tlx,List<think_liebiao> list,List<think_shenhe> list1,String time,OutputStream out) throws Exception {
		Document document = new Document();
		PdfWriter writer = PdfWriter.getInstance(document, out);
		BaseFont bfChinese = BaseFont.createFont("simhei.ttf",
				BaseFont.IDENTITY_H, false);
		Font fontChinese = new Font(bfChinese, 12, Font.NORMAL);
		float[] widths = {0.125f,0.125f,0.18f,0.07f,0.1f,0.15f,0.15f,0.1f};
		PdfPTable table = new PdfPTable(widths);
		table.setWidthPercentage(100);
		table.getDefaultCell().setBorderWidth(1);
	
        

		PdfPCell cell = null ;
		
		cell = new PdfPCell(new Paragraph("编号：——",fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_LEFT); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setBorderWidth(0);
		cell.setFixedHeight(50f);
		cell.setColspan(2);
		table.addCell(cell);
		cell = new PdfPCell(new Paragraph(" "));
		cell.setHorizontalAlignment(Element.ALIGN_LEFT); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setBorderWidth(0);
		cell.setFixedHeight(50f);
		cell.setColspan(2);
		table.addCell(cell);
		cell = new PdfPCell(new Paragraph(" "));
		cell.setHorizontalAlignment(Element.ALIGN_LEFT); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setBorderWidth(0);
		cell.setFixedHeight(50f);
		cell.setColspan(2);
		table.addCell(cell);
		
		cell = new PdfPCell(new Paragraph("流水号："+tlx.getBh()+"",fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_LEFT); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setBorderWidth(0);
		cell.setFixedHeight(50f);
		cell.setColspan(2);
		table.addCell(cell);
		
		//第一行
		cell = new PdfPCell(new Paragraph("联系人",fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setFixedHeight(50f);
		cell.setRowspan(2);
		cell.setColspan(2);
		table.addCell(cell);
		
		cell = new PdfPCell(new Paragraph(tlx.getLianxiren(),fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setRowspan(2);
		cell.setColspan(2);
		table.addCell(cell);
		
		
		cell = new PdfPCell(new Paragraph("联系电话（手机）",fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setRowspan(2);
		cell.setColspan(2);
		table.addCell(cell);
		
		cell = new PdfPCell(new Paragraph(tlx.getLianxidh(),fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setRowspan(2);
		cell.setColspan(2);
		table.addCell(cell);
		
		//第二行
		cell = new PdfPCell(new Paragraph("使用部门",fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setFixedHeight(30f);
		cell.setColspan(2);
		table.addCell(cell);
		
		cell = new PdfPCell(new Paragraph(tlx.getDw_mc(),fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中
		cell.setColspan(2);
		table.addCell(cell);
		
		cell = new PdfPCell(new Paragraph("供货时间",fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setColspan(2);
		table.addCell(cell);
		
		cell = new PdfPCell(new Paragraph(tlx.getGonghuosj(),fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setColspan(2);
		table.addCell(cell);
		
		//第三行
		cell = new PdfPCell(new Paragraph("经费来源",fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中
		cell.setFixedHeight(50f);
		cell.setRowspan(2);
		table.addCell(cell);
		
		cell = new PdfPCell(new Paragraph("经费名称",fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中
		table.addCell(cell);
		
		cell = new PdfPCell(new Paragraph(tlx.getJingfeimc(),fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setColspan(2);
		table.addCell(cell);
		
		cell = new PdfPCell(new Paragraph("预算金额（元）",fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setColspan(2);
		cell.setRowspan(2);
		table.addCell(cell);
		cell = new PdfPCell(new Paragraph(tlx.getYusuanje(),fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setColspan(2);
		cell.setRowspan(2);
		table.addCell(cell);
		
		cell = new PdfPCell(new Paragraph("经费代码",fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中
		table.addCell(cell);
		
		cell = new PdfPCell(new Paragraph(tlx.getJingfeidm(),fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setColspan(2);
		table.addCell(cell);
		
		//第四行
		cell = new PdfPCell(new Paragraph("项目负责人工号",fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setColspan(2);
		table.addCell(cell);
		
		cell = new PdfPCell(new Paragraph(tlx.getFuzerengh(),fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中
		cell.setFixedHeight(50f);
		cell.setColspan(2);
		table.addCell(cell);
		
		cell = new PdfPCell(new Paragraph("项目负责人姓名",fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setColspan(2);
		table.addCell(cell);
		
		cell = new PdfPCell(new Paragraph(tlx.getFuzerenxm(),fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setColspan(2);
		table.addCell(cell);
		
		//第五行
		cell = new PdfPCell(new Paragraph("建议采购方式",fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setFixedHeight(60f);
		cell.setColspan(2);
		cell.setRowspan(3);
		table.addCell(cell);

		
		cell = new PdfPCell(new Paragraph("",fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setFixedHeight(20f);
		cell.setColspan(4);
		cell.setRowspan(1);
		table.addCell(cell);
        
		
		cell = new PdfPCell(new Paragraph("",fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setColspan(2);
		cell.setRowspan(3);
		table.addCell(cell);
		
		cell = new PdfPCell(new Paragraph("",fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setColspan(4);
		cell.setRowspan(2);
		table.addCell(cell);
		
		//第六行
		String[] tiltles = {"序号","名称","规格（型号）","单位","数量","单价（元）","合价（元）","备注"};
		for(int i=0;i<tiltles.length;i++)
		{
			cell = new PdfPCell(new Paragraph(tiltles[i],fontChinese));
			cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
			cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
			cell.setFixedHeight(30f);
			table.addCell(cell);
		}
		
		//第7行
		int m = 0;
		int n = 0;
		for( m=0;m<list.size();m++)
		{
			cell = new PdfPCell(new Paragraph(String.valueOf(m),fontChinese));
			cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
			cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
			cell.setFixedHeight(30f);
			table.addCell(cell);
			String[] datas = {list.get(m).getMingcheng(),list.get(m).getMiaoshu(),list.get(m).getDanwei(),list.get(m).getShuliang(),list.get(m).getDanjia(),list.get(m).getHejia(),list.get(m).getBeizhu()};
			for( n=0;n<datas.length;n++)
			{
				cell = new PdfPCell(new Paragraph(datas[n],fontChinese));
				cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
				cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
				cell.setFixedHeight(40f);
				table.addCell(cell);
			}

		}
		/*for(int m =0;m<list.size();m++)
		{
			cell = new PdfPCell(new Paragraph("1",fontChinese));
			cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
			cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
			cell.setFixedHeight(50f);
			table.addCell(cell);
			String[] datas = {list.get(m).getMingcheng(),list.get(m).getMiaoshu(),list.get(m).getDanwei(),list.get(m).getShuliang(),list.get(m).getDanjia(),list.get(m).getHejia(),list.get(m).getBeizhu()};
			for(int n=0;n<datas.length;n++)
			{
				if(datas[n].length()>=10)
				{
					datas[n] = datas[n].substring(0, 10);
					datas[n]+="..";
				}
				cell = new PdfPCell(new Paragraph(datas[n],fontChinese));
				cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
				cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
				table.addCell(cell);
			}
		}*/
		//第八行
		cell = new PdfPCell(new Paragraph("合计金额："+tlx.getHejije()+"",fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setFixedHeight(30f);
		cell.setColspan(8);
		table.addCell(cell);
		
		//第九行
		cell = new PdfPCell(new Paragraph("经费负责人审核：\n(签名)",fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setFixedHeight(30f);
		cell.setColspan(2);
		cell.setRowspan(2);
		table.addCell(cell);
		
		cell = new PdfPCell(new Paragraph("同意\n\t签名:"+list1.get(0).getSh_ren()+" "+list1.get(0).getSh_riqi()+"",fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setFixedHeight(30f);
		cell.setColspan(6);
		cell.setRowspan(2);
		table.addCell(cell);
		
		//第十行
		
		cell = new PdfPCell(new Paragraph("委托人审批：\n(签名)",fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setFixedHeight(30f);
		cell.setColspan(2);
		cell.setRowspan(2);
		table.addCell(cell);
		
		cell = new PdfPCell(new Paragraph("同意\n\t签名:"+list1.get(1).getSh_ren()+"  "+list1.get(1).getSh_riqi()+"",fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setFixedHeight(30f);
		cell.setColspan(6);
		cell.setRowspan(2);
		table.addCell(cell);
		
		//第11行
		cell = new PdfPCell(new Paragraph("计财处审批：\n(签名或盖章)",fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setFixedHeight(30f);
		cell.setColspan(2);
		cell.setRowspan(2);
		table.addCell(cell);

		cell = new PdfPCell(new Paragraph("经费代码",fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setFixedHeight(30f);
		cell.setColspan(2);
		table.addCell(cell);
		
		cell = new PdfPCell(new Paragraph(tlx.getJingfeidm(),fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setFixedHeight(30f);
		cell.setColspan(2);
		table.addCell(cell);
		
		cell = new PdfPCell(new Paragraph(list1.get(2).getSh_riqi(),fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setFixedHeight(30f);
		cell.setColspan(2);
		cell.setRowspan(2);
		table.addCell(cell);
		
		cell = new PdfPCell(new Paragraph("采购方式",fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setFixedHeight(30f);
		cell.setColspan(2);
		table.addCell(cell);
		
		cell = new PdfPCell(new Paragraph(tlx.getCaigoufs(),fontChinese));
		cell.setHorizontalAlignment(Element.ALIGN_CENTER); //水平居中
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE); //垂直居中 
		cell.setFixedHeight(30f);
		cell.setColspan(2);
		table.addCell(cell);
		
		
		document.open();		
		String myString = "http://localhost:8080/SchoolPurchase/checkApplyServlet?bh="+tlx.getBh()+"&&sign=3";
		//String myString = "http://www.google.com"; 
		BarcodeQRCode qrcode = new BarcodeQRCode(myString.trim(), 1, 1, null);  
		Image qrcodeImage = qrcode.getImage();   
		qrcodeImage.scaleAbsolute(mmTopx(19), mmTopx(17));
		qrcodeImage.setAlignment(Element.ALIGN_RIGHT);
		document.add(qrcodeImage);
		document.add(new Paragraph("\n"));
		Paragraph p = new Paragraph("中国计量学院货物类采购任务书",fontChinese);
		p.setAlignment(Element.ALIGN_CENTER);
		document.add(p);
		document.add(new Paragraph("\n"));
		
		document.add(table);
		
		PdfContentByte canvas = writer.getDirectContent();
        Rectangle rect;
        PdfFormField field;
        PdfAppearance[] onOff = new PdfAppearance[2];
        onOff[0] = canvas.createAppearance(10, 10);
        onOff[0].setRGBColorStroke(0, 0, 0);
        onOff[0].rectangle(1, 1, 9, 9);
        onOff[0].stroke();
        onOff[1] = canvas.createAppearance(10, 10);
        onOff[1].setRGBColorFill(255, 255, 255);
        onOff[1].rectangle(1, 1, 9, 9);
        onOff[1].fillStroke();
        onOff[1].moveTo(1, 5);
        onOff[1].setRGBColorStroke(0, 0, 0);
        onOff[1].lineTo(5, 1);
        onOff[1].moveTo(5, 1);
        onOff[1].lineTo(9,9 );
        onOff[1].stroke();
        RadioCheckField checkbox;
        Font fontChinese1 = new Font(bfChinese, 10, Font.NORMAL);
        
        String[] LANGUAGES = { "采购中心采购", "部门自行采购", "公开招标", "邀请招标", "竞争性谈判","协议采购","单一来源采购","其它" };
        rect = new Rectangle(280, 450, 290, 440);
        checkbox = new RadioCheckField(writer, rect, LANGUAGES[0], "Yes");
        field = checkbox.getCheckField();
        if(tlx.getCaigoufs().contains(LANGUAGES[0]))
        {
       	 field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", onOff[1]);
        }
        else
        {
       	 field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", onOff[0]);
        }
        //field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Yes", onOff[0]);
        //ield.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", onOff[1]);
        writer.addAnnotation(field);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase(LANGUAGES[0], fontChinese), 300, 440, 0);
        
        rect = new Rectangle(450, 430, 460, 440);
        checkbox = new RadioCheckField(writer, rect, LANGUAGES[1], "Yes");
        field = checkbox.getCheckField();
        //field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Yes", onOff[0]);
        //field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", onOff[1]);
        if(tlx.getCaigoufs().contains(LANGUAGES[1]))
        {
       	 field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", onOff[1]);
        }
        else
        {
       	 field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", onOff[0]);
        }
        writer.addAnnotation(field);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase(LANGUAGES[1], fontChinese), 470, 430, 0);
        
        for(int i=2;i<LANGUAGES.length;i++)
        {
        	if(i>=5)
        	{
        	 rect = new Rectangle(200+(i-5)*80, 410, 210+(i-5)*80, 400);
	         checkbox = new RadioCheckField(writer, rect, LANGUAGES[0], "Yes");
	         field = checkbox.getCheckField();
	         if(tlx.getCaigoufs().contains(LANGUAGES[i]))
	         {
	        	 field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", onOff[1]);
	         }
	         else
	         {
	        	 field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", onOff[0]);
	         }
	         //field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Yes", onOff[0]);
	        // field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", onOff[0]);
	         writer.addAnnotation(field);
	         ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
	        		 new Phrase(LANGUAGES[i], fontChinese1), 215+(i-5)*80, 400, 0);
        	}
        	else
        	{
      	       	 rect = new Rectangle(200+(i-2)*80, 430, 210+(i-2)*80, 420);
    	         checkbox = new RadioCheckField(writer, rect, LANGUAGES[0], "Yes");
    	         field = checkbox.getCheckField();
    	         if(tlx.getCaigoufs().contains(LANGUAGES[i]))
    	         {
    	        	 field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", onOff[1]);
    	         }
    	         else
    	         {
    	        	 field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", onOff[0]);
    	         }
    	         //field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Yes", onOff[0]);
    	         //field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", onOff[1]);
    	         writer.addAnnotation(field);
    	         ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
    	             new Phrase(LANGUAGES[i], fontChinese1), 215+(i-2)*80, 420, 0);
        	}
;
        }
		document.close();
	}
	
	public static float mmTopx(float mm){
	     mm = (float) (mm *3.8) ;
	     return mm ;
	    }
	
	public String getTime(long interval)
	{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		  Date beginTime = null;
		try {
			beginTime = sdf.parse("1970-01-01 12:53:30");
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		  //System.out.println(interval);
		  long l = (beginTime.getTime()+interval*1000);
		//  //System.out.println(sdf.format(l));
		
		return sdf.format(l);
	}

}
